package com.iflytek.controller;

import com.iflytek.entity.Answer;
import com.iflytek.service.AnswerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import java.util.Date;

@Controller
public class AnswerController {

    @Autowired
    private AnswerService answerService;

    //新增评论
    @PostMapping("/addAnswer")
    public String answerAdd(Answer answer, RedirectAttributes redirectAttributes) {
        System.out.println(answer);
        answer.setAnswerDate(new Date());
        answerService.save(answer);
        redirectAttributes.addAttribute("id", answer.getQuestionId());
        return "redirect:questionDetail";
    }


}
